<?php

class AnotacaoDao extends Dao {

    public function injectDependencies() {

    }

    public function findByUser($IDUsuario) {
        $this->initConnection();
        $StSql = TQuery::getSqlFindNotesByUser($IDUsuario);
        $tQuery = $this->tMysqli->exec($StSql);
        $ArNotes = array();
        while ($ArNotesData = mysqli_fetch_assoc($tQuery)) {
            $ArNotes[] = new Anotacao($ArNotesData);
        }
        $this->closeConnection();
        return $ArNotes;
    }

    public function findById($IDAnotacao) {
        $this->initConnection();
        $StSql = TQuery::getSqlFindNotesById($IDAnotacao);
        $tQuery = $this->tMysqli->exec($StSql);
        while ($ArNotesData = mysqli_fetch_assoc($tQuery)) {
            $Anotacao = new Anotacao($ArNotesData);
        }
        $this->closeConnection();
        return isset($Anotacao) ? $Anotacao : false;
    }

    public function save($IDUsuario, $ArDados) {
        $this->initConnection();
        $StSql = TQuery::getSqlInsertNote($IDUsuario, $ArDados);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function update($IDUsuario, $ArDados) {
        $this->initConnection();
        $StSql = TQuery::getSqlUpdateNote($IDUsuario, $ArDados);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

    public function delete($IDAnotacao) {
        $this->initConnection();
        $StSql = TQuery::getSqlDeleteNote($IDAnotacao);
        $this->tMysqli->exec($StSql);
        $BoReturn = $this->tMysqli->lastQueryReturn();
        $this->closeConnection();
        return $BoReturn;
    }

}

?>
